//
//  ZMSearchNavView.m
//  CenturyCity
//
//  Created by beisheng03 on 2017/12/20.
//  Copyright © 2017年 beisheng. All rights reserved.
//

#import "ZMSearchNavView.h"
#import "BaseViewController.h"
@interface ZMSearchNavView ()<UITextFieldDelegate>

@property (weak, nonatomic) IBOutlet UIButton *bgBtn;
@property (weak, nonatomic) IBOutlet UIView *topBgView;
@property (weak, nonatomic) IBOutlet UIView *bottomBgView;

@end

@implementation ZMSearchNavView

- (void)awakeFromNib{
    
    
    [super awakeFromNib];
    
    self.bgBtn.layer.cornerRadius = 5;
    
    self.bgBtn.layer.masksToBounds = YES;
    
    self.searchTextField.tintColor = themeColor;
    
    
    self.topBgView.backgroundColor = themeColor;
    
    self.bottomBgView.backgroundColor = themeColor;

    
    self.calcelBtn.titleLabel.font = MYFONT(16);
    
    self.searchTextField.font = MYFONT(15);
    
    self.searchTextField.placeholder = @"输入关键字搜索";
    
    
    self.searchTextField.delegate = self;
    
    self.searchTextField.returnKeyType = UIReturnKeySearch;
    
    
}


- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    
    for (NSString *temp in myViewModel.searchHistory.searchHistoryStrs) {
        
        if ([temp isEqualToString:[NSString stringWithFormat:@"%@%@",self.type,textField.text]]) {
            
//            self.searchTextField.text = temp;
            
            if ([self.delegate respondsToSelector:@selector(reternBtnDidClick:)]) {
                [self.delegate reternBtnDidClick:textField.text];
            }
            
                        
            [textField resignFirstResponder];
            
            
            return YES;
        }
    }
    
    if (textField.text.length > 0) {
        
        [myViewModel.searchHistory.searchHistoryStrs addObject:[NSString stringWithFormat:@"%@%@",self.type,textField.text]];
        
        if ([self.delegate respondsToSelector:@selector(reternBtnDidClick:)]) {
            [self.delegate reternBtnDidClick:textField.text];
        }

        
        [textField resignFirstResponder];
    }
    
   
    
    
    return YES;
}


- (IBAction)cancelBtnDidTap:(UIButton *)sender {
    
    [self.viewController dismissViewControllerAnimated:YES completion:nil];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
